<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文件上传界面</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            font-family: Arial, sans-serif;
            background-color: #f3f4f6;
        }
        .container {
            text-align: center;
            width: 100%;
            max-width: 600px;
            padding: 20px;
        }
        .chat-box {
            border-radius: 8px;
            border: 1px solid #ddd;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            margin-bottom: 20px;
        }
        .message {
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 10px;
            color: #333;
        }
        .input-section {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }
        #fileInput {
            padding: 8px;
            font-size: 16px;
        }
        .upload-button {
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
            font-size: 16px;
            border-radius: 4px;
        }
        .upload-button:hover {
            background-color: #45a049;
        }
        .status-message {
            margin-top: 20px;
            font-size: 16px;
            color: #555;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="chat-box">
            <p class="message">上传文件</p>
            <div class="input-section">
                <input type="file" id="fileInput" />
                <button class="upload-button" onclick="uploadFile()">上传文件</button>
            </div>
        </div>
        <p id="statusMessage" class="status-message"></p>
    </div>

    <script>
        function uploadFile() {
            const fileInput = document.getElementById("fileInput");
            const statusMessage = document.getElementById("statusMessage");

            if (fileInput.files.length === 0) {
                statusMessage.textContent = "请选择一个文件上传。";
                return;
            }

            const file = fileInput.files[0];
            const formData = new FormData();
            formData.append("file", file);

            fetch("http://127.0.0.1:8000/uploading", {
                method: "POST",
                body: formData,
            })
            .then(response => response.json())
            .then(data => {
                statusMessage.textContent = "文件上传成功!";
            })
            .catch(error => {
                console.error("上传失败:", error);
                statusMessage.textContent = "文件上传失败，请重试。";
            });
        }
    </script>
</body>
</html>
